package com.hao.springboot02web.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/user")
public class LoginController {
    @RequestMapping("/login")
    public String login(@RequestParam("username") String username, @RequestParam("password") String password, Model model, HttpSession session){
        if (username!=null && "123456".equals(password)){
            session.setAttribute("loginUsername",username);
            return "redirect:/main.html";
        }else {
            model.addAttribute("msg","用户名或密码错误！");
            return "index";
        }
    }
    @RequestMapping("/logOut")
    public String  logOut(HttpSession session){
        session.invalidate();
        return "index";
    }
}
